package com.rest.demo.io;

import java.io.*;

/**
 * @author Administrator
 * @decription
 * @Date 2018-02-05 14:08
 */
public class InputStreamDemo {
    public static void main(String[] args) {
        InputStream is = null;
        StringBuffer sb = new StringBuffer();
        try {
            is = new FileInputStream("D:\\Documents\\Downloads\\info.php");
            byte[] buff = new byte[100];
            int b = -1;
            while((b = is.read(buff)) != -1) {
                sb.append(new String(buff,0,b));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(sb.toString());

        try {
            File file = new File("F:\\out.txt");
            is = new FileInputStream(file);
            byte[] buff = new byte[((int) file.length())];
            is.read(buff);
            System.out.println(new String(buff));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
